using System;
using System.Collections.Generic;
using System.Linq;
namespace TTSoft.MyApp.Repositories
{
	#region using
	using TTSoft.MyApp.Models;
	#endregion
	public class ChiTietPhieuMuonRepository
	{
		public static List<ChiTietPhieuMuon> SelectAll()
		{
			return DataContext.Instance.ChiTietPhieuMuon.ToList();
		}

		public static ChiTietPhieuMuon SelectByID(int idchitietphieumuon)
		{
			return DataContext.Instance.ChiTietPhieuMuon.FirstOrDefault(item => item.IDChiTietPhieuMuon == idchitietphieumuon );
		}

		public static bool Insert(ChiTietPhieuMuon obj)
		{
			try
			{
				DataContext.Instance.ChiTietPhieuMuon.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(int idchitietphieumuon)
		{
			try
			{
				var delitem = DataContext.Instance.ChiTietPhieuMuon.FirstOrDefault(item => item.IDChiTietPhieuMuon == idchitietphieumuon );
				DataContext.Instance.ChiTietPhieuMuon.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<ChiTietPhieuMuon> RetrieveByID(int idchitietphieumuon)
		{
			return (from item in DataContext.Instance.ChiTietPhieuMuon where  item.IDChiTietPhieuMuon == idchitietphieumuon  select item).ToList();
		}

		public static List<ChiTietPhieuMuon> SelectByIDPhieuMuon(int idphieumuon)
		{
			var lstItem = (from item in DataContext.Instance.ChiTietPhieuMuon where item.IDPhieuMuon == idphieumuon select item).ToList();
			return lstItem;
		}

		public static List<ChiTietPhieuMuon> SelectByIDTaiLieu(int idtailieu)
		{
			var lstItem = (from item in DataContext.Instance.ChiTietPhieuMuon where item.IDTaiLieu == idtailieu select item).ToList();
			return lstItem;
		}

	}
}